<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"/>
    <title>概况</title>
    <link rel="stylesheet" type="text/css" href="../../leaflet/leaflet.css"/>
    <link rel="stylesheet" type="text/css" href="../../leaflet/leaflet.marker.highlight.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/map.css"/>
    <script src="../../js/lib/jquery-3.2.1.min.js"></script>
    <script src="../../leaflet/leaflet.js"></script>
    <script src="../../leaflet/leaflet.marker.highlight.js"></script>
</head>
<body>
<div id="map"></div>

<div id="layerControl">
    <div onclick="floorControl.click(0)" class="floorBtn">F5</div>
    <div onclick="floorControl.click(1)" class="floorBtn">F4</div>
    <div onclick="floorControl.click(2)" class="floorBtn">F3</div>
    <div onclick="floorControl.click(3)" class="floorBtn">F2</div>
    <div onclick="floorControl.click(4)" class="floorBtn">F1</div>
</div>
<div id="toolPanel">

</div>
<script src="../../js/common.js"></script>
<script src="../../js/mapSource.js"></script>
<script src="../../js/layer.js"></script>
<script src="../../js/UI/floorControl.js"></script>
<script src="../../js/indoorMap.js"></script>
<script src="../../js/pgrouting.js"></script>
<script src="../../js/measure.js"></script>
<script src="../../js/plotting.js"></script>
<script>
    layerManager.setMap(map);
    layerManager.setBaseLayer(BaseLayers.getMapBoxUrl(), BaseLayers.getLayerDetails(0).id, BaseLayers.getToken());
    map.fitBounds([[34.26327, 112.715096],
        [34.989103, 114.21727]]);

    map.addEventListener('click', function (e) {
        //移除上次查询图层
        removeTempLayer();
        var x1 = e.latlng.lat - 0.05;
        var x2 = e.latlng.lat + 0.05;
        var y1 = e.latlng.lng - 0.075;
        var y2 = e.latlng.lng + 0.075;
        var x11=e.latlng.lat - 0.02;
        var x21=e.latlng.lat + 0.02;
        var y11=e.latlng.lng - 0.03;
        var y21=e.latlng.lng + 0.03;
        //画出查询范围矩形
        var latLngs=[
            [x11,y11],
            [x11,y21],
            [x21,y21],
            [x21,y11],
            [x11,y11]
        ];
        L.polyline(latLngs, {color: 'red',attribution:"queryTemp"}).addTo(map);

        var params = {
            SERVICE: "WMS",
            VERSION: "1.1.1",
            REQUEST: "GetFeatureInfo",
            QUERY_LAYERS: "power:linkageunit,power:DangerousArea,power:fire_Enterprise,power:xfll,power:xfss",
            BBOX: y1 + "," + x1 + "," + y2 + "," + x2,
            SRS: "EPSG:4326",
            INFO_FORMAT: "application/json",
            FEATURE_COUNT: 500,
            X: "50",
            Y: "50",
            WIDTH: "101",
            HEIGHT: "101",
            layers: "power:linkageunit,power:DangerousArea,power:fire_Enterprise,power:xfll,power:xfss",
            TRANSPARENT: true
        };
        $.get('http://19.16.71.127:8080/geoserver/power/wms', params, function (data, status) {
            if (status == "success") {
                console.log(data);
                if (data.features.length > 0) {
                    data.features.forEach(function (feature) {
                        addMarkerAndPopup(feature.geometry.coordinates[1],feature.geometry.coordinates[0],feature.properties.name)
                    })
                }
            }
        });
    });


    function addMarkerAndPopup(lat, lng, text) {
        var marker=L.marker([lat, lng],{attribution:"queryTemp"}).addTo(map);
        marker.bindPopup(text,{autoClose:false}).openPopup();
    }
    
    function removeTempLayer() {
        map.eachLayer(function (layer) {
            if (layer.getAttribution() =="queryTemp") {
                map.removeLayer(layer);
            }
        });
    }

    var locateMarker;

    function addLocateMarker(lat, lng) {
        if (map.hasLayer(locateMarker)) {
            map.removeLayer(locateMarker);
        }
        locateMarker = L.marker([lat, lng], {highlight: 'temporary'}).addTo(map);
    }

    //接收蓝牙结果
    function addLocation(x, y) {
        var b = -0.00000813 * x - 0.0000079 * y + 113.5582199;
        var l = -0.00000742 * y + 0.00000647 * x + 34.8252123;
        addFlicker(l, b);
    }

    //移除标记
    function stopLocation() {
        map.removeLayer(flicker);
    }
</script>
</body>
</html>